﻿using System;
using System.Linq;
using AppDomainToolkit;
using ZilLion.Core.Log;
using ZilLion.Core.TaskManager.Client.Core;
using ZilLion.TaskManager.Entity.Entity;
using ZilLion.TaskManager.Repository;

namespace ZilLion.Core.TaskManager.Client.Command
{
    /// <summary>
    ///     关闭任务命令
    /// </summary>
    [Serializable]
    public class StopTaskCommand : BaseCommand
    {
        private readonly TaskConfigRespository _taskConfigRespository = new TaskConfigRespository();


        public override void Execute()
        {
            TaskConfig taskConfig = null;
            var response = _taskConfigRespository.GetTaskConfigById(CommandInfo.Taskid);

            if ((response != null) && (response.TaskConfigList != null))
                taskConfig = response.TaskConfigList.FirstOrDefault();

            if (taskConfig == null)
            {
                ZilLionLogManager.GetLogger().Warn($"{CommandInfo.Taskid}找不到对应CONFIG");
            }

            else
            {
                TaskExcuteProvider.GetInstance().PauseTask(taskConfig);
            }
        }
    }
}